package com.eastfair.venueservice.controller;

import com.eastfair.venueservice.dto.ExhibitionSpaceDrawingDTO;
import com.eastfair.venueservice.entity.ExhibitionSpaceDrawing;
import com.eastfair.venueservice.dto.ExhibitionSpaceDrawingSaveDTO;
import com.eastfair.venueservice.dto.ExhibitionSpaceDrawingUpdateDTO;
import com.eastfair.venueservice.dto.ExhibitionSpaceDrawingPageQuery;
import com.eastfair.venueservice.service.ExhibitionSpaceDrawingService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ExhibitionSpaceDrawingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 展会展厅图纸
 * </p>
 *
 * @author dqq
 * @date 2022-11-03
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionSpaceDrawing")
@Api(value = "ExhibitionSpaceDrawing", tags = "展会展厅图纸")
@PreAuth(replace = "venueservice:exhibitionSpaceDrawing:")
public class ExhibitionSpaceDrawingController extends SuperController<ExhibitionSpaceDrawingService, Long, ExhibitionSpaceDrawing, ExhibitionSpaceDrawingPageQuery, ExhibitionSpaceDrawingSaveDTO, ExhibitionSpaceDrawingUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ExhibitionSpaceDrawingService exhibitionSpaceDrawingService;

    @Override
    public void handlerResult(IPage<ExhibitionSpaceDrawing> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionSpaceDrawing> exhibitionSpaceDrawingList = list
                .stream()
                .map((map) -> ExhibitionSpaceDrawing.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(exhibitionSpaceDrawingList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionSpaceDrawingPageQuery> params) {
        ExhibitionSpaceDrawingPageQuery pageQuery = params.getModel();
    }

    /**
     * 查询展会展厅图纸VO.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("查询展会展厅图纸VO")
    @PostMapping("/query/exhibitionSpaceDrawing")
    public R<List<ExhibitionSpaceDrawingVO>> queryExhibitionSpaceDrawing(@RequestBody ExhibitionSpaceDrawingDTO query) {
        log.info("queryExhibitionSpaceDrawing - 查询展会展厅图纸VO, query={}", query);
        List<ExhibitionSpaceDrawingVO> list = exhibitionSpaceDrawingService.listExhibitionSpaceDrawingVO(query);
        return R.successDef(list);
    }
}
